<template>
	<view class="all-list">
		<!-- 搜索列表 -->
		<block v-for="(item, index) in dataList" :key="index">
			<view class="cl-box" @click="watchLive(item)">
				<!-- <view > -->
				<image class="cl-img" mode="aspectFill" :src="item.livepic"></image>
				<view v-if="item.liveStatus !='2'"
					:class="item.liveStatus =='1'?'status':item.liveStatus =='0'?'status status-active':'status status-end'">
					<image class="status-icon" src="../../static/zhibo.png"></image>
					{{item.liveStatus =='1'?'未开始':item.liveStatus =='0'?'直播中':item.flvurl?'可回看':'已结束'}}
				</view>
				<view v-else class="status status-active">
					<image class="status-icon" src="../../static/zhibo.png"></image>{{item.flvurl?'可回看':'已结束'}}
				</view>
				<!-- </view> -->
				<view class="cl-info">
					<view class="cl-right">
						<view class="cl-title">{{item.livetitle}}</view>
					</view>
					<view class="doctor">
						<block v-for="(o,i) in item.expertVOList" :key="i">
							<image class="doctor-img" mode="aspectFit" :src="o.avatar" @tap="selectD(o)"></image>
						</block>
						<image class="doctor-img" src="../../static/Frame.png"></image>
						<view class="on-air">开播时间:{{item.timetitle.slice(0,16)}}</view>
					</view>
					<view class="cl-author">
						<view class="author-info">
							<view class="author-hosp">{{selcet.name || ''}}{{selcet.department || ''}} {{selcet.rankName || ''}}</view>
						</view>
					</view>
					<!-- <block v-for="(o,i) in item.expertVOList" :key="i">
						<view class="cl-author">
							<image class="author-img" mode="aspectFit" :src="o.avatar"></image>
							<view class="author-info">
								<view class="author-name">{{o.name||''}}</view>
							</view>
						</view>
						<view class="cl-author">
							<view class="author-info" style="width: 460rpx;">
								<view class="author-hosp">{{o.department || ''}} {{o.rankName || ''}}</view>
							</view>
						</view>
					</block> -->
					<view class="cl-author">
						<!-- {{calculateCountdown( item.starttime)}} -->
						<view class="live-time">
							<image class="lt-icon" src="../../static/sc.png"></image>
							{{item.collectCount}}
						</view>
						<view class="live-time bo">
							<image class="lt-icon" src="../../static/bf.png"></image>
							{{item.viewperson}}
						</view>
						<view style="flex:1;display: flex;justify-content: flex-end;">
							<block v-if="item.liveStatus=='1'">
								<view class="cl-btn cl-btn-orange" v-if="item.userLiveStatus =='0'"
									@click.stop="reservation(item.id,index)">立即预约</view>
								<view class="cl-btn cl-btn-grey" v-else @click.stop="reservation(item.id,index)">取消预约</view>
							</block>
							<view class="cl-btn" v-if="item.liveStatus =='0'">正在直播</view>
						</view>
					</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	import {
		reservationLive,
	} from '@/util/index.js'
	export default {
		name: "preview-list",
		//属性
		props: {
			dataList: {
				type: Array,
				default: []
			}
		},
		watch: {
			// dataList: {
			// 	handler(value) {
			// 		// 如果sectionList发生改变，重新初始化选项列表信息
			// 		value.forEach(item => {
			// 			this.calculateCountdown(item.starttime)
			// 		})

			// 	},
			// 	deep: true
			// },
		},
		data() {
			return {
				maskState: 0,
				content: '',
				focus: false,
				selcet: {}
			};
		},
		created() {},
		methods: {
			selectD(v){
				this.selcet = v
			},
			// 倒计时计算方法
			calculateCountdown(targetDate) {
				targetDate = new Date(targetDate)
				// 获取当前时间
				const now = new Date().getTime();
				// 计算时间差（毫秒）
				const distance = targetDate - now;
				// 如果时间已过或正好到达
				if (distance <= 0) {
					return '';
				}
				// setTimeout(() => {
				// 	this.calculateCountdown()
				// }, 1000)
				// 计算天、时、分、秒
				const days = Math.floor(distance / (1000 * 60 * 60 * 24));
				const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
				const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
				const seconds = Math.floor((distance % (1000 * 60)) / 1000);
				return `${days}天${hours}时${minutes}分`
			},
			watchLive(item) {
				// if (item.liveStatus == '0') {
				// 	uni.showToast({
				// 		title: '直播未开始，请耐心等待...',
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				uni.navigateTo({
					url: `../../articleVideo/live-video/live-video?id=${item.id}&liveStatus=${item.liveStatus}`
				})
			},
			reservation(id, index) {
				reservationLive({
					liveId: id
				}).then((res) => {
					uni.showToast({
						title: '操作成功！',
						icon: 'none'
					})
					this.$emit('refreshLive')
				})
			},

		}

	}
</script>

<style lang="less">
	.all-list {
		width: 100%;
		// background: #FFFFFF;
		padding: 0 20rpx;
		box-sizing: border-box;
		// margin: auto;
		// border-radius: 20rpx 20rpx 20rpx 20rpx;
	}

	.cl-box {
		width: 100%;
		display: flex;
		background: #FFFFFF;
		box-shadow: 0rpx 2rpx 6rpx 0rpx rgba(156, 194, 192, 0.36);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 24rpx 15rpx;
		position: relative;
		margin-bottom: 24rpx;

		.cl-img {
			width: 180rpx;
			height: 180rpx;
			display: block;
			flex: 0 0 180rpx;
			background-color: #FFFFFF;
			// border-radius: 10rpx;
			// image {
			// 	width: 100%;
			// 	height: 100%;
			// }
		}

		.cl-info {
			flex: 1;
			// flex-basis: calc(100% - 15px);
			// width: 450rpx;
			box-sizing: border-box;
			padding-left: 15rpx;
			box-sizing: border-box;

			.cl-right {}

			.doctor {
				width: 100%;
				display: flex;
				align-items: center;

				.doctor-img {
					width: 36rpx;
					height: 36rpx;
					border-radius: 50%;
					margin-right: 4rpx;
				}

				.on-air {
					font-size: 20rpx;
					color: #666666;
				}
			}

			.cl-title {
				font-weight: 500;
				font-size: 28rpx;
				color: #333333;
				// text-overflow: ellipsis;
				overflow: hidden;
				// white-space: nowrap;
				// width: 100%;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 1;
				line-height: 1.5;
				max-height: 1.5em;
				display: -webkit-box;
			}

			.cl-author {
				display: flex;
				align-items: center;
				padding: 5rpx 0;
				width: 100%;

				.live-time {
					font-size: 20rpx;
					color: #666666;
					background: #FFF0D2;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					padding: 8rpx 12rpx;
					margin-right: 16rpx;

					.lt-icon {
						width: 20rpx;
						height: 20rpx;
						margin-right: 8rpx;
					}
				}

				.bo {
					background: #DBEEFF;
				}

				.author-img {
					width: 32rpx;
					height: 32rpx;
					border-radius: 50%;
					margin-right: 10rpx;
					background-color: #FFFFFF;
				}

				.author-info {
					width: 100%;
					display: flex;

					.author-name {
						font-weight: 500;
						font-size: 24rpx;
						color: #333333;
						margin-right: 10rpx;
					}

					view {
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
						line-height: 38rpx;
					}

					.author-hosp {
						font-size: 24rpx;
						color: #999999;
					}


				}

				.cl-btn {
					min-width: 144rpx;
					height: 50rpx;
					background-color: #FFB51D;
					color: #FFFFFF;
					line-height: 50rpx;
					display: inline-block;
					// text-align: center;
					border-radius: 25rpx;
					font-size: 24rpx;
					flex-basis: auto;
					// flex: 0 0 120rpx;
					padding: 0 34rpx;
				}

				.cl-btn-grey {
					background: #DDDDDD;
				}

				.cl-btn-orange {
					background: #00D9D0;
				}
			}

			.live-box {
				
			}
		}

		.status {
			position: absolute;
			top: 0;
			left: 0;
			background: #F8B858;
			border-radius: 16rpx 0  16rpx 0;
			font-size: 16rpx;
			color: #FFFFFF;
			width: 106rpx;
			height: 34rpx;
			display: flex;
			align-items: center;
			padding: 0 10rpx;

			.status-icon {
				width: 30rpx;
				height: 30rpx;
				margin-right: 4rpx;
			}
		}

		.status-active {
			background: #00C8C8;
		}

		.status-end {
			background: #9b9b9b;
		}
	}
</style>
